const fs = require('fs').promises;
const path = require('path');

// 要遍历的文件夹路径
const folderPath = './packages';

async function createReadmeInFolders(folderPath) {
  try {
    // 读取文件夹中的所有内容
    const entries = await fs.readdir(folderPath, { withFileTypes: true });

    for (let entry of entries) {
      const fullPath = path.join(folderPath, entry.name);

      // 检查是否为目录
      if (entry.isDirectory()) {
        const readmePath = path.join(fullPath, 'README.md');

        // 创建 readme.md 文件
        await fs.writeFile(readmePath, '# Project Readme\n\nAdd your project documentation here.', 'utf8');
        console.log(`Readme created in: ${readmePath}`);
      }
    }
  } catch (err) {
    console.error('Error creating readme files:', err);
  }
}

// 调用函数
createReadmeInFolders(folderPath);